package
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import sparrowGui.SparrowGUI;
	import sparrowGui.components.HScrollBar;
	import sparrowGui.components.ItemGroup;
	import sparrowGui.components.PageList;
	import sparrowGui.components.QueueAlert;
	import sparrowGui.components.SCheckBox;
	import sparrowGui.components.SCombobox;
	import sparrowGui.components.SPopupMenu;
	import sparrowGui.components.SRadioGroup;
	import sparrowGui.components.STextArea;
	import sparrowGui.components.SToolTip;
	import sparrowGui.components.SWindow;
	import sparrowGui.components.ScrollList;
	import sparrowGui.components.ScrollPanel;
	import sparrowGui.components.ScrollTree;
	import sparrowGui.components.VScrollBar;
	import sparrowGui.components.item.SButton;
	import sparrowGui.components.item.SItem;
	import sparrowGui.components.item.SRichButton;
	import sparrowGui.components.item.STreeItem;
	import sparrowGui.event.ListEvent;
	import sparrowGui.uiStyle.UIStyleMgr;
	
	/**
	 * 用来测试麻雀GUI v1.0
	 * @author Pelephone
	 * @website http://cnblogs.com/pelephone
	 */
	[SWF(backgroundColor="0xFFFFFF",width="800",height="480",frameRate="25")]
	public class SparrowTest extends Sprite
	{
		public function SparrowTest()
		{
			new SparrowGUI(this,550,400);
			testItem();
			testScrollBar();
			testList();
			testTree();
			testWindow();
			testTip();
			testAlert();
			testCombobox();
			testPageList();
			testTextArea();
		}
		
		private function testTree():void
		{
			var tr:ScrollTree = new ScrollTree();
			tr.y = 100;
			tr.x = 300;
			
			var xml:XML = XML(
				<tree>
						<node nodeId='1' pid='' skinCls='' txtName='11' selected='' />
						<node nodeId='2' pid='' skinCls='' txtName='22' selected='' />
						<node nodeId='3' pid='1' skinCls='' txtName='33' selected='' />
						<node nodeId='4' pid='1' skinCls='' txtName='44' selected='' />
						<node nodeId='5' pid='1' skinCls='' txtName='44' selected='' />
				</tree>
			);
			
			addChild(tr);
			tr.update(xml);
		}
		
		/**
		 * 测试文本域
		 */
		private function testTextArea():void
		{
			var ta:STextArea = new STextArea();
			ta.width = 100;
			ta.height = 100;
			ta.x = 480;
			ta.y = 100;
			ta.update("asd\n222222\n333\n444\n555\n666\n777\n222222\n333\n444\n555\n666\n7" +
				"77\n222222\n333\n444\n555\n666\n777\n222222\n333\n444\n555\n666\n777");
			
			addChild(ta);
		}
		
		private function testAlert():void
		{
			var dp:DisplayObject = getChildByName("sixBtn");
			dp.addEventListener(MouseEvent.CLICK,ff);
			new QueueAlert(this);
			
			/*			var al:SAlert = new SAlert(this,null);
			al.addEventListener(AlertEvent.ALERT_CLOSE,ff2);
			*/
			function ff(e:MouseEvent):void
			{
				//				al.show("aa","yes|no",ff2);
				QueueAlert.getIns().alertOk("asdf",ff2);
				QueueAlert.getIns().alertYesNo("asd22f",ff2);
			}
			
			
			function ff2(e:Event):void
			{
				trace(e);
			}
			
			dp = getChildByName("treeItem");
			dp.addEventListener(MouseEvent.CLICK,ff3);
			var pop:SPopupMenu = new SPopupMenu(this);
			pop.addEventListener(ListEvent.LIST_ITEM_SELECT,ff2);
			
			function ff3(e:MouseEvent):void
			{
				pop.show([11,22,33,44,55],dp);
			}
		}
		
		/**
		 * 测试item相关
		 */
		private function testItem():void
		{
			var aa:SItem = new SRichButton("checkItem");
			aa.update("多选");
			aa.y = 300;
			addChild(aa);
			
			aa = new SRichButton("radioItem");
			aa.update("单选");
			aa.y = 300;
			aa.x = 100;
			addChild(aa);
			
			/*			aa.addEventListener(MouseEvent.CLICK,testScrollBar);
			aa.addEventListener(MouseEvent.CLICK,testCombobox);
			aa.removeTypeListeners(MouseEvent.CLICK);*/
			
			aa = new SRichButton();
			aa.update("六态按钮");
			aa.name = "sixBtn"
			aa.y = 300;
			aa.x = 200;
			addChild(aa);
			
			var trm:STreeItem = new STreeItem();
			trm.update("树形按钮");
			trm.name = "treeItem";
			trm.y = 300;
			trm.x = 400;
			addChild(trm);
		}
		
		/**
		 * 测试滚动条
		 */
		private function testScrollBar():void
		{
			var s:VScrollBar = new VScrollBar();
			s.height = 100;
			s.setSliderParams(1,100);
			s.x = 10;
			s.y = 150;
			addChild(s);
			
			var sh:HScrollBar = new HScrollBar();
			sh.width = 100;
			sh.setSliderParams(1,100);
			sh.x = 150;
			sh.y = 250;
			addChild(sh);
		}
		
		/**
		 * 测试列表
		 */
		private function testList():void
		{
			var ls:ItemGroup = new SRadioGroup();
			ls.update([11,22,33,44]);
			addChild(ls);
			
			var cb:SCheckBox = new SCheckBox();
			cb.colNum = 3;
			cb.update([11,22,33,44,55,66,77,88,99,00,11,22,33,44,55,66,77,88,99,00]);
			addChild(cb);
			
			var sp:ScrollPanel = new ScrollPanel();
			sp.x = 300;
			sp.source = cb;
			addChild(sp);
			
			var rls:ScrollList = new ScrollList();
			rls.update([11,22,33,44,55,66,77]);
			rls.x = 50;
			rls.y = 100;
			addChild(rls);
		}
		
		private function testWindow():void
		{
			var w:SWindow = new SWindow();
			w.name = "ww1";
			w.x = 140;
			w.y = 40;
			addChild(w);
		}
		
		public var tip:SToolTip;
		
		private function testTip():void
		{
			tip = new SToolTip(this);
			tip.width = 80;
			tip.height = 100;
			
			var abc:DisplayObject = this.getChildByName("ww1");
			var dp:SItem = new SButton();
			dp.update("四态按钮");
			dp.name = "state4";
			dp.y = 300;
			dp.x = 300;
			addChild(dp);
			
			tip.addTip(abc,"测试一下");
		}
		
		private function testCombobox():void
		{
			var cbx:SCombobox = new SCombobox(this);
			cbx.update([11,22,33]);
			cbx.x = 200;
			cbx.y = 200;
			addChild(cbx);
		}
		
		private function testPageList():void
		{
			var pl:PageList = new PageList();
			pl.x = 400;
			addChild(pl);
			
			var pb:DisplayObject = UIStyleMgr.getIns().createSkinUI("pageBox");//new PageBox();
			pb.x = 400;
			pb.y = 200;
			addChild(pb);
			
			pl.setPageBox(pb);
			pl.update([11,22,33,44,55,66,77,88,99,00,111,112,113,114,115]);
		}
	}
}